<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">


<ui:composition template="/templates/templateAdmin.xhtml">
	<ui:define name="conteudo">
		<h:form>
			<p:dataTable var="escola" id="listarEscola"
				value="#{mBEscola.escolas}"
				emptyMessage="Não há escolas cadastradas" rows="10" paginator="true">
				<p:column filterBy="#{escola.nome}" filterMatchMode="contains">
					<f:facet name="header">
						Nome
					</f:facet>
					<p:commandLink value="#{escola.nome}" oncomplete="escolaDialog.show()" update="@form">
						<f:setPropertyActionListener target="#{mBEscola.escolaVisualizacao}" value="#{escola}"/>
					</p:commandLink>
				</p:column>
				<p:column>
					<f:facet name="header">
						Operações
					</f:facet>
					<p:commandButton value="Editar" ajax="false">
						<f:setPropertyActionListener target="#{mBEscola.escola}"
							value="#{escola}" />
					</p:commandButton>
					<p:commandButton value="Excluir" oncomplete="confirmation.show()">
						<f:setPropertyActionListener target="#{mBEscola.escola}"
							value="#{escola}" />
					</p:commandButton>


					<p:confirmDialog id="confirmDialog"
						message="Tem certeza que deseja excluir o aluno?" header="Aviso"
						severity="alert" widgetVar="confirmation">

						<p:commandButton id="confirm" value="Sim"
							oncomplete="confirmation.hide()" action="#{mBEscola.excluir}"
							ajax="false" />

						<p:commandButton id="decline" value="Não"
							onclick="confirmation.hide()" action="#{mBEscola.limpar}" />

					</p:confirmDialog>

				</p:column>
			</p:dataTable>
			<p:dialog widgetVar="escolaDialog" header="Escola">
				<ui:include src="../../comum/escola.xhtml">
					<ui:param name="escola" value="#{mBEscola.escolaVisualizacao}"/>
				</ui:include>
			</p:dialog>
		</h:form>
		<p:panel header="Escola">
			<h:form>
				<p:panel header="Dados Gerais">
					<h:panelGrid columns="2">
						<h:outputLabel value="Nome*:" />
						<p:inputText value="#{mBEscola.escola.nome}" size="50"
							required="true" requiredMessage="Inisira o nome" />
						<h:outputLabel value="Sigla:" />
						<p:inputText value="#{mBEscola.escola.sigla}" size="20" />
						<h:outputLabel value="Razão Social:" />
						<p:inputText value="#{mBEscola.escola.sigla}" size="40" />
						<h:outputLabel value="Localização:" />
						<p:selectOneRadio value="#{mBEscola.escola.localizacao}">
							<f:selectItem itemLabel="Rural" itemValue="Rural"/>
							<f:selectItem itemLabel="Urbana" itemValue="Urbana"/>
						</p:selectOneRadio>
					</h:panelGrid>
				</p:panel>
				<p:panel header="Endereço">
					<h:panelGrid columns="2">
						<h:outputLabel value="Cep:" />
						<p:inputMask value="#{mBEscola.escola.cep}" size="8"
							mask="99999-999" />
						<h:outputLabel value="Rua:" />
						<p:inputText value="#{mBEscola.escola.rua}" size="60" />
						<h:outputLabel value="Número:" />
						<p:inputText value="#{mBEscola.escola.numero}" size="4" />
						<h:outputLabel value="Bairro:" />
						<p:inputText value="#{mBEscola.escola.bairro}" />
					</h:panelGrid>
				</p:panel>
				<p:panel header="Contato">
					<h:panelGrid columns="2">
						<h:outputLabel value="Telefone 1:" />
						<p:inputMask mask="(99)9999-9999"
							value="#{mBEscola.escola.telefone1}" />
						<h:outputLabel value="Telefone 2:" />
						<p:inputMask mask="(99)9999-9999"
							value="#{mBEscola.escola.telefone2}" />
						<h:outputLabel value="Email:" />
						<p:inputText value="#{mBEscola.escola.email}" size="50"
							validatorMessage="Email inválido">
							<f:validateRegex
								pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
						</p:inputText>
					</h:panelGrid>
				</p:panel>

				<h:outputLabel value="" />
				<h:panelGroup rendered="#{mBEscola.escola.id == NULL}">
					<p:commandButton value="Cadastrar" ajax="false"
						action="#{mBEscola.cadastrar}" />
					<p:commandButton value="Cancelar" ajax="false" />
				</h:panelGroup>
				<h:panelGroup rendered="#{mBEscola.escola.id != NULL}">
					<p:commandButton value="Editar" ajax="false"
						action="#{mBEscola.editar}" />
					<p:commandButton onclick="form.reset()" value="Cancelar" ajax="false"
						action="#{mBEscola.limpar}" />
				</h:panelGroup>

			</h:form>
		</p:panel>
	</ui:define>
</ui:composition>
</html>